from selenium.webdriver.common.by import By


class Login(object):
    loginPage = (By.XPATH, ".//div[@class='content']")
    loginFrame = (By.XPATH, ".//iframe")
    txtLogin = (By.ID, "UserName")
    txtPassword = (By.ID, "Password")
    btnSignIn = (By.XPATH, ".//button[@type='submit']")
    btnAllow = (By.XPATH, ".//button[@id='oauthAllow']")

class MainFrame(object):
    frame = (By.ID, "body")
    btnAllDevices = (By.XPATH, ".//*[@class='mainMenu']/li")
    btnAddGroup = (By.XPATH, ".//*[@class='mainMenu']//span[@class='addGroup']")
    listGroups = (By.XPATH, ".//*[@class='groupList']/ul")
    btnUserSettings = (By.XPATH, ".//*[@class='personal']/div[@class='name']/span")
    btnUser = (By.XPATH, ".//li[@data-active-window='users-dialog']")
    btnLicense = (By.XPATH, ".//li[@data-active-window='about-dialog']")
    btnSupport = (By.XPATH, ".//li[@data-active-window='help-dialog']")
    btnSignOut = (By.XPATH, ".//li[@onclick='logout()']")
    accountTable = (By.XPATH, ".//div[@class='accountTable']/table")
    formLoader = (By.XPATH, ".//div[@class='formLoader']")

    trialFrame = (By.XPATH, ".//div[@class='rightBar']/div[@class='trial']/p")

    txtSearch = (By.XPATH, ".//form[@id='searchForm']/div/input")
    btnSearch = (By.XPATH, ".//form[@id='searchForm']/div/div[@class='magnifier']")
    cmbFilterBy = (By.XPATH, ".//div[contains(@class, 'filterBar')]/div[1]/div")
    cmbFilterType = (By.XPATH, ".//div[contains(@class, 'filterBar')]/div[2]/div")
    btnCharts = (By.XPATH, ".//div[@class='icons']/div[@class='chart']")
    btnFilter = (By.XPATH, './/div[@class="icons"]/div[@class="filter"]')
    charts = (By.XPATH, ".//div[@class='chartContent']")

    class ListGroupItem(object):
        labelGroupName = (By.XPATH, ".//a/span")
        btnGroupSettings = (By.XPATH, ".//span[@class='editGroupIcon']")
        btnEditGroup = (By.XPATH, ".//li[@class='edit']")
        btnDeleteGroup = (By.XPATH, ".//li[@class='delete']")
        menuEditDelete = (By.XPATH, ".//div[contains(@class, 'dropDownGroup')]")
        listItem = (By.XPATH, "li")

class Group(object):
    frame = (By.ID, "add-group-dialog")
    txtGroupName = (By.ID, "Group")
    btnAdd = (By.XPATH, ".//button[@class='mdl mb10']") #[Contains(@onclick, 'submit')]
    btnCancel = (By.XPATH, ".//button[contains(@onclick, 'close_dialog')]")
    btnSubmit = (By.XPATH, ".//button[contains(@onclick, 'submit')]")


class UserSettings(object):
    btnUser = (By.XPATH, ".//a[@href='/web/users/users']")
    btnLicense = (By.XPATH, ".//a[@href='/web/settings/license']")
    btnSupport = (By.XPATH, ".//a[@href='/web/settings/help']")
    btnClose = (By.XPATH, ".//button[@class='mdl']")
    rightFrameLoader = (By.XPATH, './/div[@class="rightpref"]/div[@class="formLoader"]')
    winDialogUserSettings = (By.ID, "options-dialog")

    class User(object):
        btnAddUser = (By.XPATH, ".//div[@class='add addUser']")
        tableUserRoles = (By.XPATH, './/div[@class="jspPane"]/table')
        deleteUser = (By.XPATH, './/div[@class="user-tables"]//ul/li[@data-type="delete"]')
        editUser = (By.XPATH, './/div[@class="user-tables"]//ul/li[@data-type="edit"]')

    class AddUser(object):
        txtEmail = (By.XPATH, ".//input[@data-name='Email']")
        txtName = (By.XPATH, ".//input[@data-name='Name']")
        txtPassword = (By.XPATH, ".//input[@data-name='Password']")
        txtConfirmPassword = (By.XPATH, ".//input[@data-name='Confirm password']")
        cbRole = (By.XPATH, './/*[@id="addUserForm"]//div[@class="airSelecter"]/div')
        btnAdd = (By.XPATH, ".//button[@class='small mb10']")
        btnCancel = (By.XPATH, ".//button[@class='small']")

    class DeleteUser(object):
        frame = (By.ID, "delete-user-dialog")
        btnDelete = (By.XPATH, ".//button[contains(@onclick, 'submit')]")
        btnCancel = (By.XPATH, ".//button[contains(@onclick, 'close_dialog')]")

    class EditUser(object):
        frame = (By.ID, "edit-user-dialog")
        cbRole = (By.XPATH, ".//form[@id='editUserForm']//div[@class='airSelecter']/div[contains(@class, 'selecter')]")
        btnSave = (By.XPATH, ".//button[contains(@onclick, 'submit')]")
        btnCancel = (By.XPATH, ".//button[contains(@onclick, 'close_dialog')]")

    class License(object):
        linkByNow = (By.XPATH, ".//table//a[@href='http://airbackup.com/buy']")

    class Support(object):
        linkFAQ = (By.XPATH, ".//a[@href='http://airbackup.com/support/center']")
        linkSubmitTicket = (By.XPATH, ".//a[@href='http://airbackup.com/support/request']")
        linkFeedback = (By.XPATH, ".//p[@class='faqLink']/a")


class Devices(object):
    btnClose = (By.XPATH, '//div[@id="show-properties-dialog"]//div[@class="btnBlock"]/button')

    btnOverview = (By.XPATH, './/a[@href="/web/properties/overview"]')
    btnBackup = (By.XPATH, './/a[@href="/web/properties/backup"]')
    btnStatistic = (By.XPATH, './/a[@href="/web/properties/statistic"]')
    btnAudit = (By.XPATH, './/a[@href="/web/properties/audit"]')
    btnErrors = (By.XPATH, './/a[@href="/web/properties/errors"]')
    groupComboBox = (By.XPATH, './/form[@id="modifyAccountForm"]/div[@class="airSelecter"]/div')


    class Overview(object):
        tableEmailOs = (By.XPATH, './/div[@class="jspPane"]/table[1]')
        tableDataSources = (By.XPATH, './/div[@class="jspPane"]/table[@class="tbl m0"]')

    class Backup(object):
        tableBackupInfo = (By.XPATH, './/table[@class="tbl backup"]')

    class Statistic(object):
        tableGeneral = (By.XPATH, './/div[@class="jspPane"]/table[1]')
        tableAdvanced = (By.XPATH, './/div[@class="jspPane"]/table[2]')
        tableFiles = (By.XPATH, './/div[@class="jspPane"]/table[3]')

    class Errors(object):
        tableErrors = (By.XPATH, './/div[@class="jspPane"]/table[@class="tbl backup"]')
